#ifndef ACO_ACOTEST_H
#define ACO_ACOTEST_H

#include "tool/define.h"
#include "tool/tool.h"
#include <QPoint>

class acoTest {
public:
    acoTest() {}

    ~acoTest () {}

    std::vector<QPoint> process();

    void getMatrix(std::vector<std::vector<int>> matrix) {
        vert = matrix;
    }

    void setStartStop (QPoint sta, QPoint sto) {
        start.first = sta.x()/scale;
        start.second = sta.y()/scale;
        stop.first = sto.x()/scale;
        stop.second = sto.y()/scale;
        return;
    }

    void setScale(int s) {
        scale = s;
    }

    double getMin() {
        return min;
    }
private:
    std::vector<QPoint> qtDraw;

    std::string file_name;
    std::vector<std::vector<int>> vert;//栅格矩阵
    int citys;//城市数量
    int rows;
    int scale;
    std::vector<std::vector<double>> pheromone;//信息素
    std::vector<std::vector<double>> heuristic;//启发式值(η)eta
    std::vector<std::vector<double>> tau;//信息素矩阵
    std::vector<std::vector<bool>> adjacencyMatrix;//栅格矩阵转换成的邻接矩阵(可达矩阵)
    float pheromone_0;//pheromone初始值，这里是1/(avg*N)其中avg为图网中所有边边权的平均数
    //bool initialize = true;
    int ants = 0;//蚂蚁数量
    int MAX, iteration;//最大迭代次数，迭代计数变量
    int alpha, beta;//参数
    int minNum = 0;
    double min = INT32_MAX;
    double dist;
    double rho;
    double deltaTau;
    pair_int start;
    pair_int stop;
    pair_int current;
    pair_int last;
    const double Q = 2.0;
    std::vector<std::vector<pair_int>> pathes;
    std::vector<std::vector<pair_int>> bestPathes;
    std::vector<pair_int> bestPathe;
    std::vector<double> mins;

    void G2D();

    void updateD(std::vector<pair_int> passBy);

    bool judgeAdjacency(int p1, int p2);

    bool judgeGo(int cur, int next);

    void init();

    pair_int selectNext(pair_int i);

    void updatePheromone(int j);

    void optimizationRoute();

    //void routeToPoint();
};

#endif //ACO_ACOTEST_H
